// 等待DOM加载完成
document.addEventListener('DOMContentLoaded', function() {
    // 获取元素
    const mainHeart = document.getElementById('main-heart');
    const yesBtn = document.getElementById('yes-btn');
    const noBtn = document.getElementById('no-btn');
    const heartsContainer = document.getElementById('hearts-container');
    
    // 创建飘落的心形
    function createFloatingHearts() {
        setInterval(() => {
            const heart = document.createElement('div');
            heart.classList.add('floating-heart');
            heart.innerHTML = '❤';
            heart.style.left = Math.random() * 100 + 'vw';
            heart.style.fontSize = (Math.random() * 20 + 10) + 'px';
            heart.style.opacity = Math.random() * 0.5 + 0.3;
            heart.style.animation = `fall ${Math.random() * 5 + 5}s linear forwards`;
            
            document.body.appendChild(heart);
            
            // 移除心形元素以避免内存泄漏
            setTimeout(() => {
                heart.remove();
            }, 10000);
        }, 300);
    }
    
    // 添加飘落心形的CSS
    const style = document.createElement('style');
    style.innerHTML = `
        @keyframes fall {
            to {
                transform: translateY(100vh) rotate(360deg);
                opacity: 0;
            }
        }
    `;
    document.head.appendChild(style);
    
    // 主心形点击效果
    mainHeart.addEventListener('click', function() {
        this.style.animation = 'none';
        void this.offsetWidth; // 触发重绘
        this.style.animation = 'heartbeat 1.5s infinite';
        
        // 创建爆炸心形效果
        for (let i = 0; i < 20; i++) {
            const miniHeart = document.createElement('div');
            miniHeart.classList.add('floating-heart');
            miniHeart.innerHTML = '❤';
            miniHeart.style.position = 'absolute';
            miniHeart.style.left = '50%';
            miniHeart.style.top = '50%';
            miniHeart.style.fontSize = '1.5rem';
            miniHeart.style.color = '#ff4d8d';
            miniHeart.style.opacity = '1';
            miniHeart.style.transition = 'all 1s ease-out';
            miniHeart.style.transform = `translate(-50%, -50)`;
            
            document.body.appendChild(miniHeart);
            
            // 随机方向散开
            setTimeout(() => {
                const angle = Math.random() * Math.PI * 2;
                const distance = Math.random() * 200 + 100;
                const x = Math.cos(angle) * distance;
                const y = Math.sin(angle) * distance;
                
                miniHeart.style.transform = `translate(${x}px, ${y}px)`;
                miniHeart.style.opacity = '0';
                
                // 移除元素
                setTimeout(() => {
                    miniHeart.remove();
                }, 1000);
            }, 10);
        }
    });
    
    // "我也喜欢你"按钮点击事件
    yesBtn.addEventListener('click', function() {
        // 创建庆祝效果
        document.body.style.background = 'linear-gradient(135deg, #ffb8e0, #ff7bac)';
        
        // 更改消息
        const messageContainer = document.querySelector('.message-container');
        messageContainer.innerHTML = `
            <p class="confession" style="animation: none; opacity: 1;">谢谢你！</p>
            <p class="message" style="animation: none; opacity: 1;">这真是我收到过最美好的回应</p>
            <p class="message" style="animation: none; opacity: 1;">期待与你的每一次相遇 ❤</p>
        `;
        
        // 隐藏按钮
        document.querySelector('.button-container').style.display = 'none';
        
        // 增加心形动画
        createIntenseHearts();
    });
    
    // "再考虑一下"按钮事件
    noBtn.addEventListener('click', function() {
        // 移动按钮（逃避效果）
        const moveBtn = () => {
            const maxX = window.innerWidth - this.offsetWidth;
            const maxY = window.innerHeight - this.offsetHeight;
            const randomX = Math.floor(Math.random() * maxX);
            const randomY = Math.floor(Math.random() * maxY);
            
            this.style.position = 'absolute';
            this.style.left = randomX + 'px';
            this.style.top = randomY + 'px';
        };
        
        moveBtn();
        
        // 添加鼠标悬停时继续移动的效果
        noBtn.addEventListener('mouseover', moveBtn);
        
        // 增加"再考虑一下"文本大小
        const messages = document.querySelectorAll('.message');
        messages[messages.length - 1].innerHTML = '请再给我一次机会！';
        messages[messages.length - 1].style.fontSize = '1.5rem';
        messages[messages.length - 1].style.color = '#ff4d8d';
        messages[messages.length - 1].style.fontWeight = 'bold';
    });
    
    // 创建更密集的心形效果
    function createIntenseHearts() {
        setInterval(() => {
            const heart = document.createElement('div');
            heart.classList.add('floating-heart');
            heart.innerHTML = '❤';
            heart.style.left = Math.random() * 100 + 'vw';
            heart.style.fontSize = (Math.random() * 25 + 15) + 'px';
            heart.style.color = '#ff4d8d';
            heart.style.opacity = Math.random() * 0.7 + 0.3;
            heart.style.animation = `fall ${Math.random() * 3 + 2}s linear forwards`;
            
            document.body.appendChild(heart);
            
            // 移除心形元素
            setTimeout(() => {
                heart.remove();
            }, 8000);
        }, 100);
    }
    
    // 启动飘落的心形
    createFloatingHearts();
});